from django import forms
from django.contrib import admin
from .models import *

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = ('id', 'order_code', 'buyer', 'seller', 'product', 'status', 'create_time')
    list_filter = ('status', 'create_time', 'deliver_time')
    search_fields = ('order_code', 'buyer__username', 'seller__username', 'product__name')
    raw_id_fields = ('buyer', 'seller', 'product', 'address')
    date_hierarchy = 'create_time'
    ordering = ('-create_time',)
    list_select_related = ('buyer', 'seller', 'product')

@admin.register(OrderLog)
class OrderLogAdmin(admin.ModelAdmin):
    list_display = ('id', 'order', 'action', 'operator', 'created_at')
    list_filter = ('action', 'created_at')
    search_fields = ('order__order_code', 'operator__username')
    raw_id_fields = ('order', 'operator')
    date_hierarchy = 'created_at'

@admin.register(Reviews) 
class ReviewAdmin(admin.ModelAdmin):
    list_display = ('id', 'order', 'buyer', 'rating', 'review_time')
    list_filter = ('rating', 'review_time')
    search_fields = ('order__order_code', 'buyer__username')
    raw_id_fields = ('order', 'buyer')
    readonly_fields = ('review_time',)